/*
 * bsp_xzc_dy1.c
 *
 *  Created on: 2022年7月26日
 *      Author: kaijunHuang
 */


#include "main.h"
#include "bsp_xzc_dy1.h"
#include "bsp_includes.h"

#if XZC_DY1_MODULE_ENABLED

DataBuffer dataBuffer[DATABUFFERSIZE];
ErrorBuffer ErrorID[DATABUFFERSIZE];
short temperature = 0;
uint8_t serialNum = 0;
uint32_t communicationErrorFlag;
uint32_t receiveFlag = 0xFFFFFFFF;

float power = 0;

DataBuffer diYa1Data[UPLOADDATASIZE];

void DataInitForTest(void)
{
	//电风扇
	dataBuffer[DATABUFFERSIZE-1].data[1] = 0x05;
	//电源模块
	dataBuffer[DATABUFFERSIZE-2].data[1] = 0xFF;
	dataBuffer[DATABUFFERSIZE-3].data[1] = 0x0F;
	//通讯
	communicationErrorFlag = 0x00000000;
	//主控通讯异常(未收到显控控制报文)
	communicationCan1ErrorFlag = 1;
	//驱动1
	dataBuffer[0].data[1] = 240;
	dataBuffer[0].data[2] = 0x00;
	dataBuffer[0].data[3] = 20;
	dataBuffer[0].data[4] = 0x00;
	dataBuffer[0].data[5] = 0x00;
	dataBuffer[0].data[6] = 0x00;
	dataBuffer[0].data[7] = 0x03;
	//驱动2
	dataBuffer[1].data[1] = 240;
	dataBuffer[1].data[2] = 0x00;
	dataBuffer[1].data[3] = 20;
	dataBuffer[1].data[4] = 0x00;
	dataBuffer[1].data[5] = 0x00;
	dataBuffer[1].data[6] = 0x01;
	dataBuffer[1].data[7] = 0x00;
	//驱动3
	dataBuffer[2].data[1] = 240;
	dataBuffer[2].data[2] = 0x00;
	dataBuffer[2].data[3] = 20;
	dataBuffer[2].data[4] = 0x00;
	dataBuffer[2].data[5] = 0x00;
	dataBuffer[2].data[6] = 0x00;
	dataBuffer[2].data[7] = 0x00;
	//驱动4
	dataBuffer[3].data[1] = 240;
	dataBuffer[3].data[2] = 0x00;
	dataBuffer[3].data[3] = 20;
	dataBuffer[3].data[4] = 0x00;
	dataBuffer[3].data[5] = 0x00;
	dataBuffer[3].data[6] = 0x00;
	dataBuffer[3].data[7] = 0x00;
    //驱动5
	dataBuffer[4].data[1] = 0x18;
	dataBuffer[4].data[2] = 0x15;
	dataBuffer[4].data[3] = 20;
	dataBuffer[4].data[4] = 0x00;
	dataBuffer[4].data[5] = 0x00;
	dataBuffer[4].data[6] = 0x00;
	dataBuffer[4].data[7] = 0x00;
    //导航设备
	dataBuffer[5].data[1] = 0x18;
	dataBuffer[5].data[2] = 0x15;
	dataBuffer[5].data[3] = 20;
	dataBuffer[5].data[4] = 0x00;
	dataBuffer[5].data[5] = 0x00;
	dataBuffer[5].data[6] = 0x00;
	dataBuffer[5].data[7] = 0x00;
    //综合管理设备
	dataBuffer[6].data[1] = 0x18;
	dataBuffer[6].data[2] = 0x15;
	dataBuffer[6].data[3] = 20;
	dataBuffer[6].data[4] = 0x00;
	dataBuffer[6].data[5] = 0x00;
	dataBuffer[6].data[6] = 0x00;
	dataBuffer[6].data[7] = 0x00;
    //发控控制
	dataBuffer[7].data[1] = 0x18;
	dataBuffer[7].data[2] = 0x15;
	dataBuffer[7].data[3] = 20;
	dataBuffer[7].data[4] = 0x00;
	dataBuffer[7].data[5] = 0x00;
	dataBuffer[7].data[6] = 0x00;
	dataBuffer[7].data[7] = 0x00;
    //交换机
	dataBuffer[8].data[1] = 0x18;
	dataBuffer[8].data[2] = 0x15;
	dataBuffer[8].data[3] = 20;
	dataBuffer[8].data[4] = 0x00;
	dataBuffer[8].data[5] = 0x00;
	dataBuffer[8].data[6] = 0x00;
	dataBuffer[8].data[7] = 0x00;
    //车体控制
	dataBuffer[9].data[1] = 0x18;
	dataBuffer[9].data[2] = 0x15;
	dataBuffer[9].data[3] = 20;
	dataBuffer[9].data[4] = 0x00;
	dataBuffer[9].data[5] = 0x00;
	dataBuffer[9].data[6] = 0x00;
	dataBuffer[9].data[7] = 0x00;
    //通讯设备
	dataBuffer[10].data[1] = 0x18;
	dataBuffer[10].data[2] = 0x15;
	dataBuffer[10].data[3] = 20;
	dataBuffer[10].data[4] = 0x00;
	dataBuffer[10].data[5] = 0x00;
	dataBuffer[10].data[6] = 0x00;
	dataBuffer[10].data[7] = 0x00;
    //行军销解锁1
	dataBuffer[11].data[1] = 0x18;
	dataBuffer[11].data[2] = 0x15;
	dataBuffer[11].data[3] = 20;
	dataBuffer[11].data[4] = 0x00;
	dataBuffer[11].data[5] = 0x00;
	dataBuffer[11].data[6] = 0x00;
	dataBuffer[11].data[7] = 0x00;
    //行军销解锁2
	dataBuffer[12].data[1] = 0x18;
	dataBuffer[12].data[2] = 0x15;
	dataBuffer[12].data[3] = 20;
	dataBuffer[12].data[4] = 0x00;
	dataBuffer[12].data[5] = 0x00;
	dataBuffer[12].data[6] = 0x00;
	dataBuffer[12].data[7] = 0x00;
    //锁固销解锁1
	dataBuffer[13].data[1] = 0x18;
	dataBuffer[13].data[2] = 0x15;
	dataBuffer[13].data[3] = 20;
	dataBuffer[13].data[4] = 0x00;
	dataBuffer[13].data[5] = 0x00;
	dataBuffer[13].data[6] = 0x00;
	dataBuffer[13].data[7] = 0x00;
    //锁固销解锁2
	dataBuffer[14].data[1] = 0x18;
	dataBuffer[14].data[2] = 0x15;
	dataBuffer[14].data[3] = 20;
	dataBuffer[14].data[4] = 0x00;
	dataBuffer[14].data[5] = 0x00;
	dataBuffer[14].data[6] = 0x00;
	dataBuffer[14].data[7] = 0x00;
    //硅发输入
	dataBuffer[15].data[1] = 0x18;
	dataBuffer[15].data[2] = 0x15;
	dataBuffer[15].data[3] = 20;
	dataBuffer[15].data[4] = 0x00;
	dataBuffer[15].data[5] = 0x00;
	dataBuffer[15].data[6] = 0x00;
	dataBuffer[15].data[7] = 0x00;
    //高压输入
	dataBuffer[16].data[1] = 0x18;
	dataBuffer[16].data[2] = 0x15;
	dataBuffer[16].data[3] = 20;
	dataBuffer[16].data[4] = 0x00;
	dataBuffer[16].data[5] = 0x00;
	dataBuffer[16].data[6] = 0x00;
	dataBuffer[16].data[7] = 0x00;
}
void Upload_To_Xiankong()
{
//	DataInitForTest();
	diYa1Data[0].data[0] = 0x1Fu;
	diYa1Data[0].data[1] = serialNum++;
	diYa1Data[0].data[2] = dataBuffer[0].data[1];
	diYa1Data[0].data[3] = dataBuffer[0].data[2];
	diYa1Data[0].data[4] = dataBuffer[0].data[3];
	diYa1Data[0].data[5] = dataBuffer[0].data[4];
	diYa1Data[0].data[6] = dataBuffer[1].data[1];
	diYa1Data[0].data[7] = dataBuffer[1].data[2];

	diYa1Data[1].data[0] = 0x2Fu;
	diYa1Data[1].data[1] = dataBuffer[1].data[3];
	diYa1Data[1].data[2] = dataBuffer[1].data[4];
	diYa1Data[1].data[3] = dataBuffer[2].data[1];
	diYa1Data[1].data[4] = dataBuffer[2].data[2];
	diYa1Data[1].data[5] = dataBuffer[2].data[3];
	diYa1Data[1].data[6] = dataBuffer[2].data[4];
	diYa1Data[1].data[7] = dataBuffer[3].data[1];

	diYa1Data[2].data[0] = 0x3Fu;
	diYa1Data[2].data[1] = dataBuffer[3].data[2];
	diYa1Data[2].data[2] = dataBuffer[3].data[3];
	diYa1Data[2].data[3] = dataBuffer[3].data[4];
	diYa1Data[2].data[4] = dataBuffer[4].data[1];
	diYa1Data[2].data[5] = dataBuffer[4].data[2];
	diYa1Data[2].data[6] = dataBuffer[4].data[3];
	diYa1Data[2].data[7] = dataBuffer[4].data[4];

	diYa1Data[3].data[0] = 0x4Fu;
	diYa1Data[3].data[1] = dataBuffer[5].data[1];
	diYa1Data[3].data[2] = dataBuffer[5].data[2];
	diYa1Data[3].data[3] = dataBuffer[5].data[3];
	diYa1Data[3].data[4] = dataBuffer[5].data[4];
	diYa1Data[3].data[5] = dataBuffer[6].data[1];
	diYa1Data[3].data[6] = dataBuffer[6].data[2];
	diYa1Data[3].data[7] = dataBuffer[6].data[3];

	diYa1Data[4].data[0] = 0x5Fu;
	diYa1Data[4].data[1] = dataBuffer[6].data[4];
	diYa1Data[4].data[2] = dataBuffer[7].data[1];
	diYa1Data[4].data[3] = dataBuffer[7].data[2];
	diYa1Data[4].data[4] = dataBuffer[7].data[3];
	diYa1Data[4].data[5] = dataBuffer[7].data[4];
	diYa1Data[4].data[6] = dataBuffer[8].data[1];
	diYa1Data[4].data[7] = dataBuffer[8].data[2];

	diYa1Data[5].data[0] = 0x6Fu;
	diYa1Data[5].data[1] = dataBuffer[8].data[3];
	diYa1Data[5].data[2] = dataBuffer[8].data[4];
	diYa1Data[5].data[3] = dataBuffer[9].data[1];
	diYa1Data[5].data[4] = dataBuffer[9].data[2];
	diYa1Data[5].data[5] = dataBuffer[9].data[3];
	diYa1Data[5].data[6] = dataBuffer[9].data[4];
	diYa1Data[5].data[7] = dataBuffer[10].data[1];

	diYa1Data[6].data[0] = 0x7Fu;
	diYa1Data[6].data[1] = dataBuffer[10].data[2];
	diYa1Data[6].data[2] = dataBuffer[10].data[3];
	diYa1Data[6].data[3] = dataBuffer[10].data[4];
	diYa1Data[6].data[4] = dataBuffer[11].data[1];
	diYa1Data[6].data[5] = dataBuffer[11].data[2];
	diYa1Data[6].data[6] = dataBuffer[11].data[3];
	diYa1Data[6].data[7] = dataBuffer[11].data[4];

	diYa1Data[7].data[0] = 0x8Fu;
	diYa1Data[7].data[1] = dataBuffer[12].data[1];
	diYa1Data[7].data[2] = dataBuffer[12].data[2];
	diYa1Data[7].data[3] = dataBuffer[12].data[3];
	diYa1Data[7].data[4] = dataBuffer[12].data[4];
	diYa1Data[7].data[5] = dataBuffer[13].data[1];
	diYa1Data[7].data[6] = dataBuffer[13].data[2];
	diYa1Data[7].data[7] = dataBuffer[13].data[3];

	diYa1Data[8].data[0] = 0x9Fu;
	diYa1Data[8].data[1] = dataBuffer[13].data[4];
	diYa1Data[8].data[2] = dataBuffer[14].data[1];
	diYa1Data[8].data[3] = dataBuffer[14].data[2];
	diYa1Data[8].data[4] = dataBuffer[14].data[3];
	diYa1Data[8].data[5] = dataBuffer[14].data[4];
	diYa1Data[8].data[6] = dataBuffer[15].data[1];
	diYa1Data[8].data[7] = dataBuffer[15].data[2];

	diYa1Data[9].data[0] = 0xAFu;
	diYa1Data[9].data[1] = dataBuffer[15].data[3];
	diYa1Data[9].data[2] = dataBuffer[15].data[4];

	diYa1Data[9].data[3] = dataBuffer[16].data[1];
	diYa1Data[9].data[4] = dataBuffer[16].data[2];

	diYa1Data[9].data[5] = dataBuffer[16].data[3];
	diYa1Data[9].data[6] = dataBuffer[16].data[4];
	if(dataBuffer[16].data[1] == 0x00 && dataBuffer[16].data[2] == 0x00)
	{
		__NOP();
	}
	diYa1Data[9].data[7] = dataBuffer[0].data[6];

	diYa1Data[10].data[0] = 0xBFu;
	diYa1Data[10].data[1] = dataBuffer[1].data[6];
	diYa1Data[10].data[2] = dataBuffer[2].data[6];
	diYa1Data[10].data[3] = dataBuffer[3].data[6];
	diYa1Data[10].data[4] = dataBuffer[4].data[6];
	diYa1Data[10].data[5] = dataBuffer[5].data[6];
	diYa1Data[10].data[6] = dataBuffer[6].data[6];
	diYa1Data[10].data[7] = dataBuffer[7].data[6];

	diYa1Data[11].data[0] = 0xCFu;
	diYa1Data[11].data[1] = dataBuffer[8].data[6];
	diYa1Data[11].data[2] = dataBuffer[9].data[6];
	diYa1Data[11].data[3] = dataBuffer[10].data[6];
	diYa1Data[11].data[4] = dataBuffer[11].data[6];
	diYa1Data[11].data[5] = dataBuffer[12].data[6];
	diYa1Data[11].data[6] = dataBuffer[13].data[6];
	diYa1Data[11].data[7] = dataBuffer[14].data[6];

	diYa1Data[12].data[0] = 0xDFu;
	diYa1Data[12].data[1] = dataBuffer[15].data[6];
	diYa1Data[12].data[2] = dataBuffer[16].data[6];
	diYa1Data[12].data[3] = dataBuffer[0].data[7]<<6|
						   dataBuffer[1].data[7]<<4|
						   dataBuffer[2].data[7]<<2|
						   dataBuffer[3].data[7];
	diYa1Data[12].data[4] = dataBuffer[4].data[7]<<6|
						   dataBuffer[5].data[7]<<4|
						   dataBuffer[6].data[7]<<2|
						   dataBuffer[7].data[7];
	diYa1Data[12].data[5] = dataBuffer[8].data[7]<<6|
						   dataBuffer[9].data[7]<<4|
						   dataBuffer[10].data[7]<<2|
						   dataBuffer[11].data[7];
	diYa1Data[12].data[6] = dataBuffer[12].data[7]<<6|
			   	   	   	   dataBuffer[13].data[7]<<4|
						   dataBuffer[14].data[7]<<2|
						   dataBuffer[15].data[7];

	diYa1Data[12].data[7] = dataBuffer[16].data[7]<<6|
							(dataBuffer[16].data[7]&0x0c)<<2;

	if((dataBuffer[0].data[5]&              //保护功能  00:打开 11H:关闭
		dataBuffer[1].data[5]&
		dataBuffer[2].data[5]&
		dataBuffer[3].data[5]&
		dataBuffer[4].data[5]&
		dataBuffer[5].data[5]&
		dataBuffer[6].data[5]&
		dataBuffer[7].data[5]&
		dataBuffer[8].data[5]&
		dataBuffer[9].data[5]&
		dataBuffer[10].data[5]&
		dataBuffer[11].data[5]&
		dataBuffer[12].data[5]&
		dataBuffer[13].data[5]&
		dataBuffer[14].data[5]&
		dataBuffer[15].data[5]&
		dataBuffer[16].data[5]) == 0x00)
	{
		diYa1Data[12].data[7] &= 0xF0;
	}else{
		diYa1Data[12].data[7] |= 0x01;
	}

	diYa1Data[13].data[0] = 0xEFu;
	diYa1Data[13].data[1] = temperature;
	diYa1Data[13].data[2] = temperature>>8;
	//整机状态
	if(communicationCan1ErrorFlag == 1){
		diYa1Data[13].data[3] |= 0x01;
	}else{
		diYa1Data[13].data[3] &= 0xfe;
	}
	if((temperature >= 850)&&(temperature <= 1200)){
		diYa1Data[13].data[3] |= 0x40;
	}else if(temperature > 1200){
		diYa1Data[13].data[3] |= 0x20;
	}else{
		diYa1Data[13].data[3] &= 0x9f;
	}
	//风机调速板信息
	diYa1Data[13].data[4] = dataBuffer[DATABUFFERSIZE-1].data[1];
	//内部通讯
	diYa1Data[13].data[5] = (communicationErrorFlag) & 0xFF;
	diYa1Data[13].data[6] = (communicationErrorFlag>>8) & 0xFF;
	diYa1Data[13].data[7] = communicationErrorFlag>>16;

	diYa1Data[14].data[0] = 0xFFu;
	//电源模块故障信息
	diYa1Data[14].data[1] = dataBuffer[DATABUFFERSIZE-2].data[1];
	diYa1Data[14].data[2] = dataBuffer[DATABUFFERSIZE-1].data[1];
	//累计时间
	diYa1Data[14].data[3] = cumulatetime>>24;
	diYa1Data[14].data[4] = cumulatetime>>16;
	diYa1Data[14].data[5] = cumulatetime>>8;
	diYa1Data[14].data[6] = cumulatetime;


	uint8_t uiCRCNum = 0;
	for(int j = 0;j < UPLOADDATASIZE - 1;j++){
		for(int k = 0;k < 8;k++){
			uiCRCNum += diYa1Data[j].data[k];
		}
	}
	for(int j = 0;j < 7;j++){
		uiCRCNum += diYa1Data[UPLOADDATASIZE-1].data[j];
	}
	diYa1Data[UPLOADDATASIZE-1].data[7] = uiCRCNum;

	for(uint8_t i = 0; i < UPLOADDATASIZE; i ++)
	{
		BSP_CAN1_Transmit(RUNNINGFRAME, diYa1Data[i].data);
		HAL_Delay(10);
	}

	power = 0;
	for(int i = 0;i < 15;i ++){
		power += (dataBuffer[i].data[1] + (dataBuffer[i].data[2] << 8)) * (dataBuffer[i].data[3] + (dataBuffer[i].data[4]<<8));
	}
}

void BSP_CheckModulesComError()
{
	for(int j = 0; j < DATABUFFERSIZE; j ++)
	{
		ErrorID[j].errortimes++;
		if(ErrorID[j].errortimes > JUDEMENTDELAYTIMES)
		{
			receiveFlag &= ~(1<<j);
			ErrorID[j].errortimes = JUDEMENTDELAYTIMES;
		}
		communicationErrorFlag = ~ receiveFlag;
		communicationErrorFlag &= 0x01FFFF;
	}
}

void Check_ReceiveFlag(uint32_t extId)
{
	uint8_t deviceId = extId & 0xFF;
	receiveFlag |= (1 << (deviceId-1));
	ErrorID[deviceId-1].errortimes = 0;
}

void BSP_UpdateBoxState()
{
	uint8_t check =
			(dataBuffer[0].data[6]&0x1b)|
			(dataBuffer[1].data[6]&0x1b)|
			(dataBuffer[2].data[6]&0x1b)|
			(dataBuffer[3].data[6]&0x1b)|
			(dataBuffer[4].data[6]&0x1b)|
			(dataBuffer[5].data[6]&0x1b)|
			(dataBuffer[6].data[6]&0x1b)|
			(dataBuffer[7].data[6]&0x1b)|
			(dataBuffer[8].data[6]&0x1b)|
			(dataBuffer[9].data[6]&0x1b)|
			(dataBuffer[10].data[6]&0x1b)|
			(dataBuffer[11].data[6]&0x1b)|
			(dataBuffer[12].data[6]&0x1b)|
			(dataBuffer[13].data[6]&0x1b)|
			(dataBuffer[14].data[6]&0x1b)|
			(dataBuffer[15].data[6]&0x1b)|
			(dataBuffer[16].data[6]&0x1b);
		if(((check & 0x03) != 0x00) ||
			(diYa1Data[13].data[3] & 0x20) != 0x00 ||
			(diYa1Data[13].data[4]&0x7F) != 0x00   ||
			(diYa1Data[14].data[1]&0xFF) != 0x00   ||
			(diYa1Data[14].data[2]&0x0F) != 0x00
			)
		{
			// 过流故障 过压故障
			// 过温故障
			// 风机调速板
			// 电源模块故障
			boxState = BSP_FAULT;
		}
		else if((check & 0x18) != 0x00  || (diYa1Data[13].data[3] & 0x40) != 0x00)
		{
			// 过流告警 过压告警 欠压告警（输入）
			// 过温告警
			boxState = BSP_ALARM;
		}
		else
		{
			boxState = BSP_NORMAL;
		}
}

void Configure_Can1_Filter()
{
	CAN_FilterTypeDef	sFilterConfig;

	sFilterConfig.FilterBank = 0;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)CONTROLFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)CONTROLFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)SETTINGFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterMaskIdLow =  (((uint32_t)SETTINGFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan1,&sFilterConfig))
	{
		Error_Handler();
	}

	sFilterConfig.FilterBank = 1;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)READFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =  (((uint32_t)READFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh =  ((((uint32_t)VERSIONFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;;
	sFilterConfig.FilterMaskIdLow =  (((uint32_t)VERSIONFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan1,&sFilterConfig))
	{
		Error_Handler();
	}

}

void Configure_Can2_Filter()
{
	CAN_FilterTypeDef	sFilterConfig;

	sFilterConfig.FilterBank = 14;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c306101<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c306101<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)0x0c306102<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterMaskIdLow = (((uint32_t)0x0c306102<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}

	sFilterConfig.FilterBank = 15;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c306103<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c306103<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)0x0c306104<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterMaskIdLow = (((uint32_t)0x0c306104<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;
	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}

	sFilterConfig.FilterBank = 16;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c306105<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c306105<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)0x0c306106<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterMaskIdLow = (((uint32_t)0x0c306106<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;
	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}

	sFilterConfig.FilterBank = 17;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c306107<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c306107<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)0x0c306108<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;;
	sFilterConfig.FilterMaskIdLow =(((uint32_t)0x0c306108<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}

	sFilterConfig.FilterBank = 18;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c306109<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c306109<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)0x0c30610a<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;;
	sFilterConfig.FilterMaskIdLow =(((uint32_t)0x0c30610a<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}

	sFilterConfig.FilterBank = 19;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c30610b<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c30610b<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)0x0c30610c<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;;
	sFilterConfig.FilterMaskIdLow =(((uint32_t)0x0c30610c<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}


	sFilterConfig.FilterBank = 20;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c30610d<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c30610d<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)0x0c30610e<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;;
	sFilterConfig.FilterMaskIdLow =(((uint32_t)0x0c30610e<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}

	sFilterConfig.FilterBank = 21;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)SETTINGBACKFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)SETTINGBACKFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)READBACKFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;//¶ÁÈ¡±¨ÎÄID
	sFilterConfig.FilterMaskIdLow =	(((uint32_t)READBACKFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}

	sFilterConfig.FilterBank = 22;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c30610f<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c30610f<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)0x0c306110<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterMaskIdLow =(((uint32_t)0x0c306110<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}
	sFilterConfig.FilterBank = 23;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = ((((uint32_t)0x0c306111<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterIdLow =   (((uint32_t)0x0c306111<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterMaskIdHigh = ((((uint32_t)VERSIONCALLBACKFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF0000)>>16;
	sFilterConfig.FilterMaskIdLow = (((uint32_t)VERSIONCALLBACKFRAME<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

	if(HAL_CAN_ConfigFilter(&hcan2,&sFilterConfig))
	{
		Error_Handler();
	}
}

void BSP_DataInit()
{
	communicationErrorFlag = 0;
	for(uint8_t i = 0; i < DATABUFFERSIZE; i++)
	{
		dataBuffer[i].data[7] = 0x03;
	}
}

#endif
